<?php
/**
 * Created by PhpStorm.
 * User: 驭风者
 * Date: 2019/11/11
 * Time: 10:19
 */
class DB
{
    private $link;
    public function __construct($host,$test,$user,$pass)
        {
            $this->link = new PDO("mysql:host=$host;dbname=test", $user, $pass);
            $this->link->exec("set names utf8");
            $this->link->setAttribute(PDO::ATTR_ERRMODE,true);
        }

    public function getAdd($table,$data)
    {
        $v = '';
        $k = '';
        foreach($data as $key => $value){
            $v .= "'".$value."'".",";
            $k .= "$key,";
        }
        $v = substr($v,0,-1);//截取
        $k = substr($k,0,-1);
        $sql = "insert into `$table` ($k) value ($v)";

        $res = $this->link->exec($sql);
        return $res;
    }
    public  function getShow($table,$arr)
    {
        $sql= 'select  * from '.$table;

        if(!empty($arr)){
            foreach($arr as $key => $value){
                $where = "$key" .'='."'$value'";
            }-
            $sql .= ' where '.$where;
        }
        return $data;
    }

}

?>